package com.infore.operation.service.impl;

import com.github.pagehelper.PageHelper;
import com.infore.operation.entity.*;
import com.infore.operation.exception.OperationException;
import com.infore.operation.mapper.StatisticsMapper;
import com.infore.operation.mapper.UserMapper;
import com.infore.operation.service.StatisticsService;
import com.infore.operation.utils.ComparatorMap;
import com.infore.operation.utils.FileUtil;
import com.infore.operation.utils.FormatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author:wk
 * @date:Created in 10:41 2018\4\17 0017
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    private StatisticsMapper statisticsMapper;

    @Autowired
    private UserMapper userMapper;

    @Value("${imagePath}")
    private String  imagePath;

    @Value("${photoPath}")
    private String  photoPath;

    @Override
    public List<Map<String,Object>> queryFaultStatistics(String userId, String type, String startTime, String endTime, String pageNum) throws ParseException{
        UserInfoId infoId = userMapper.queryUserInfoId(userId);
        String stationSql = "select id from Station where maint_id="+userId;;
        if (infoId.getPostId()!=1
                && infoId.getPostId()!=9) {
            if (infoId.getOpId()!=null) {
                stationSql = "select id from Station where maint_id in (select id from maint_pson where op_id="+infoId.getOpId()+")";
            }
            if (infoId.getBranchId() != null) {
                stationSql = "select id from Station where maint_id in (select a.id from maint_pson a left join op_cen b on a.op_id=b.id left join branch_ofc c on b.br_id=c.id where a.branch_id="+infoId.getBranchId()+" or c.id="+infoId.getBranchId()+")";
            }
        }
        String sql = "";
        String stationSqls = "";
        if ("运营工程师".equals(infoId.getRoleName())
                || "运营主管".equals(infoId.getRoleName())
                || "运营主任".toString().equals(infoId.getRoleName())
                || "运营经理".equals(infoId.getRoleName())) {
            stationSqls = " f.STATION_ID in (" + stationSql + ")";
        }
        if (startTime != null) {
            if("".equals(stationSqls)) {
                stationSqls = " f.occur_t>'" + startTime
                        + " 00:00:00' and f.occur_t<'" + endTime + " 23:59:59'";
            }else{
                stationSqls += " and f.occur_t>'" + startTime
                        + " 00:00:00' and f.occur_t<'" + endTime + " 23:59:59'";
            }
        }
        if (type.equals("1")) {
            sql = "select b.NAME name,count(b.NAME) num from BRANCH_OFC b join MAINT_PSON m on m.BRANCH_ID = b.ID join STATION s on s.MAINT_ID=m.ID "
                    +"join FAULT_RECD f on f.STATION_ID=s.ID  "+
                    ("".equals(stationSqls)?"":"where") +stationSqls
                    +" group by b.NAME "
                    +"union all select b.NAME,count(b.NAME) from BRANCH_OFC b join OP_CEN o on o.BR_ID=b.ID "
                    +"join MAINT_PSON m on m.OP_ID = o.ID join STATION s on s.MAINT_ID=m.ID "
                    +"join FAULT_RECD f on f.STATION_ID=s.ID  "+
                    ("".equals(stationSqls)?"":"where") +stationSqls+" group by b.NAME ";
            List<Map<String,Object>> list = queryFaultDatas(sql,"fgs");
            Collections.sort(list, new ComparatorMap());
            return list;
        } else if (type.equals("2")) {
            sql = "select b.NAME name, count(b.NAME) num from FAULT_RECD as f join EQUIP as e on e.ID=f.EQUIP_ID "
                    +"join EQUIP_MODEL m on m.id=e.MODEL_ID join EQUIP_BRAND b on b.id=m.BRAND_ID  "
                    +("".equals(stationSqls)?"":"where")  +stationSqls+" group by b.NAME ";
            List<Map<String,Object>> list = queryFaultDatas(sql,"brand");
            Collections.sort(list, new ComparatorMap());
            return list;
        } else if (type.equals("3")) {
            sql = "select t.NAME name, count(t.NAME) num from FAULT_RECD as f join FAULT_TYPE t on t.ID=f.FTTP_ID  "+("".equals(stationSqls)?"":"where") +stationSqls+" group by t.NAME";
            List<Map<String,Object>> list = queryFaultDatas(sql,"type");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("5")) {
            sql = "select t.NAME name, count(t.NAME) num from FAULT_RECD as f join STATION as s on s.ID=f.STATION_ID "
                    +"join STATION_TYPE t on t.id=s.TYPE_ID  "+("".equals(stationSqls)?"":"where")
                    +stationSqls+"  group by t.NAME";
            List<Map<String,Object>> list = queryFaultDatas(sql,"ptype");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("6")) {
            sql = "select c.NAME name, count(c.NAME) num from FAULT_RECD as f join STATION as s on s.ID=f.STATION_ID "
                    +"join CONTROL_TYPE c on c.id=s.CTROL_ID  "+("".equals(stationSqls)?"":"where")
                    +stationSqls+" group by c.NAME";
            List<Map<String,Object>> list = queryFaultDatas(sql,"ctype");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("7")) {
            sql = "select m.NAME name, count(m.NAME) num from FAULT_RECD as f join STATION as s on s.ID=f.STATION_ID "
                    +"join MAINT_PSON m on m.id=s.MAINT_ID  "+("".equals(stationSqls)?"":"where")
                    +stationSqls+"  group by m.NAME";
            List<Map<String,Object>> list = queryFaultDatas(sql,"pson");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("8")) {
            sql = "select m.NAME name, count(m.NAME) num from FAULT_RECD as f join EQUIP as e on e.ID=f.EQUIP_ID "
                    +"join EQUIP_MODEL m on m.id=e.MODEL_ID join EQUIP_BRAND b on b.id=m.BRAND_ID  "+("".equals(stationSqls)?"":"where")
                    +stationSqls+" group by m.NAME ";
            List<Map<String,Object>> list = queryFaultDatas(sql,"model");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("4")) {
            sql = "select e.id,e.INSTALL_T from FAULT_RECD  f left join EQUIP  e on e.ID=f.EQUIP_ID "
                    +("".equals(stationSqls)?"":"where") +stationSqls;
            List<Map<String,Object>> faultList = statisticsMapper.queryFaultStatistics(sql);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Map<String, Integer> mapTime = new HashMap<String, Integer>();
            int numtime = 0;
            for (int i = 0; i < faultList.size(); i++) {
                if (faultList.get(i).get("INSTALL_T") != null) {
                    long time = 0;
                    time = (new Date()).getTime()
                            - sdf.parse(
                            faultList.get(i).get("INSTALL_T").toString())
                            .getTime();
                    double timenum = time
                            / (365 * 24 * 60 * 60 * 1000.0);
                    if (timenum >= 0 && timenum <= 0.5) {
                        if (mapTime.containsKey("安装半年以内")) {
                            mapTime.put("安装半年以内",
                                    mapTime.get("安装半年以内") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装半年以内", 1);
                            numtime++;
                        }
                    } else if (timenum > 0.5 && timenum <= 1) {
                        if (mapTime.containsKey("安装半年至一年")) {
                            mapTime.put("安装半年至一年",
                                    mapTime.get("安装半年至一年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装半年至一年", 1);
                            numtime++;
                        }
                    } else if (timenum > 1 && timenum <= 2) {
                        if (mapTime.containsKey("安装一年至两年")) {
                            mapTime.put("安装一年至两年",
                                    mapTime.get("安装一年至两年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装一年至两年", 1);
                            numtime++;
                        }
                    } else if (timenum > 2 && timenum <= 3) {
                        if (mapTime.containsKey("安装两年至三年")) {
                            mapTime.put("安装两年至三年",
                                    mapTime.get("安装两年至三年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装两年至三年", 1);
                            numtime++;
                        }
                    } else if (timenum > 3 && timenum <= 4) {
                        if (mapTime.containsKey("安装三年至四年")) {
                            mapTime.put("安装三年至四年",
                                    mapTime.get("安装三年至四年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装三年至四年", 1);
                            numtime++;
                        }
                    } else if (timenum > 4 && timenum <= 5) {
                        if (mapTime.containsKey("安装四年至五年")) {
                            mapTime.put("安装四年至五年",
                                    mapTime.get("安装四年至五年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装四年至五年", 1);
                            numtime++;
                        }
                    } else if (timenum > 5) {
                        if (mapTime.containsKey("安装五年以上")) {
                            mapTime.put("安装五年以上",
                                    mapTime.get("安装五年以上") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装五年以上", 1);
                            numtime++;
                        }
                    }
                } else {
                    if (mapTime.containsKey("不确定")) {
                        mapTime.put("不确定", mapTime.get("不确定") + 1);
                        numtime++;
                    } else {
                        mapTime.put("不确定", 1);
                        numtime++;
                    }
                }
            }
            List<Map<String,Object>> list = new ArrayList<>();
            for (String key : mapTime.keySet()) {
                Map<String,Object> maplist = new HashMap<String, Object>();
                maplist.put("time", key);
                maplist.put("value", mapTime.get(key));
                maplist.put(
                        "percent",
                        String.format("%.2f", mapTime.get(key)
                                / (double) numtime));
                list.add(maplist);
            }
            Collections.sort(list, new ComparatorMap());
            return list;
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> queryOperationStatistics(String userId, String type, String pageNum) throws ParseException{
        UserInfoId infoId = userMapper.queryUserInfoId(userId);
        String stationSql = "select id from Station where maint_id="+userId;
        if (infoId.getPostId()!=1
                && infoId.getPostId()!=9) {
            if (infoId.getOpId() != null) {
                stationSql = "select id from Station where maint_id in (select id from maint_pson where op_id="+infoId.getOpId()+")";
            }
            if (infoId.getBranchId() != null) {
                stationSql = "select id from Station where maint_id in (select a.id from maint_pson a left join op_cen b on a.op_id=b.id left join branch_ofc c on b.br_id=c.id where a.branch_id="+infoId.getBranchId()+" or c.id="+infoId.getBranchId()+")";
            }
        }
        String sql = "";
        List<Map<String,Object>> stationList = statisticsMapper.queryFaultStatistics(stationSql.toString());
        String stationSqls = "";
        if ("运营工程师".equals(infoId.getRoleName())
                || "运营主管".equals(infoId.getRoleName())
                || "运营主任".toString().equals(infoId.getRoleName())
                || "运营经理".equals(infoId.getRoleName())) {
            stationSqls = "where e.STATION_ID in ("+stationSql+")";
        }
        if (type.equals("1")) {
            sql = "select b.NAME name,count(b.NAME) num from BRANCH_OFC b join MAINT_PSON m on m.BRANCH_ID = b.ID  join STATION s on s.MAINT_ID=m.ID "
                    +"join EQUIP e on e.STATION_ID=s.ID "
                    +stationSqls
                    +" group by b.NAME union all select b.NAME ,count(b.NAME) from BRANCH_OFC b join  OP_CEN o on o.BR_ID=b.ID join"
                    +" MAINT_PSON m on m.OP_ID = o.ID join STATION s on s.MAINT_ID=m.ID "
                    +"join EQUIP e on e.STATION_ID=s.ID "
                    +stationSqls+" group by b.NAME";
            List<Map<String,Object>> list = queryFaultDatas(sql,"fgs");
            Collections.sort(list, new ComparatorMap());
            return list;
        } else if (type.equals("2")) {
            sql = "select b.NAME name, count(b.NAME) num from EQUIP as e "
                    +"join EQUIP_MODEL m on m.id=e.MODEL_ID join EQUIP_BRAND b on b.id=m.BRAND_ID "+stationSqls+" group by b.NAME ";
            List<Map<String,Object>> list = queryFaultDatas(sql,"brand");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("3")) {
            sql = "select t.NAME name, count(t.NAME) num from EQUIP as e join STATION as s on s.ID=e.STATION_ID "
                    +"join STATION_TYPE t on t.id=s.TYPE_ID "
                    +stationSqls+" group by t.NAME";
            List<Map<String,Object>> list = queryFaultDatas(sql,"ptype");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("5")) {
            sql = "select c.NAME name, count(c.NAME) num from EQUIP as e join STATION as s on s.ID=e.STATION_ID "
                    +"join CONTROL_TYPE c on c.id=s.CTROL_ID "
                    +stationSqls+" group by c.NAME";
            List<Map<String,Object>> list = queryFaultDatas(sql,"ctype");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("6")) {
            sql = "select m.NAME name, count(m.NAME) num from EQUIP as e join STATION as s on s.ID=e.STATION_ID "
                    +"join MAINT_PSON m on m.id=s.MAINT_ID "
                    +stationSqls+" group by m.NAME";
            List<Map<String,Object>> list = queryFaultDatas(sql,"pson");
            Collections.sort(list, new ComparatorMap());
            return list;
        }else if (type.equals("4")) {
            if (stationList!=null&&stationList.size()!=0) {
                sql = "select *from Equip where station_id in ("+stationSql+")";
            } else {
                sql = "select * from Equip";
            }
            List<Map<String,Object>> elist = statisticsMapper.queryFaultStatistics(sql);
            SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Map<String, Integer> mapTime = new HashMap<String, Integer>();
            int numtime = 0;
            for (int i = 0; i < elist.size(); i++) {
                if (elist.get(i).get("install_t") != null) {
                    long time = (new Date()).getTime()
                            - sdf.parse(elist.get(i).get("install_t").toString()).getTime();
                    double timenum = time / (365 * 24 * 60 * 60 * 1000.0);
                    if (timenum >= 0 && timenum <= 0.5) {
                        if (mapTime.containsKey("安装半年以内")) {
                            mapTime.put("安装半年以内", mapTime.get("安装半年以内") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装半年以内", 1);
                            numtime++;
                        }
                    } else if (timenum > 0.5 && timenum <= 1) {
                        if (mapTime.containsKey("安装半年至一年")) {
                            mapTime.put("安装半年至一年",
                                    mapTime.get("安装半年至一年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装半年至一年", 1);
                            numtime++;
                        }
                    } else if (timenum > 1 && timenum <= 2) {
                        if (mapTime.containsKey("安装一年至两年")) {
                            mapTime.put("安装一年至两年",
                                    mapTime.get("安装一年至两年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装一年至两年", 1);
                            numtime++;
                        }
                    } else if (timenum > 2 && timenum <= 3) {
                        if (mapTime.containsKey("安装两年至三年")) {
                            mapTime.put("安装两年至三年",
                                    mapTime.get("安装两年至三年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装两年至三年", 1);
                            numtime++;
                        }
                    } else if (timenum > 3 && timenum <= 4) {
                        if (mapTime.containsKey("安装三年至四年")) {
                            mapTime.put("安装三年至四年",
                                    mapTime.get("安装三年至四年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装三年至四年", 1);
                            numtime++;
                        }
                    } else if (timenum > 4 && timenum <= 5) {
                        if (mapTime.containsKey("安装四年至五年")) {
                            mapTime.put("安装四年至五年",
                                    mapTime.get("安装四年至五年") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装四年至五年", 1);
                            numtime++;
                        }
                    } else if (timenum > 5) {
                        if (mapTime.containsKey("安装五年以上")) {
                            mapTime.put("安装五年以上", mapTime.get("安装五年以上") + 1);
                            numtime++;
                        } else {
                            mapTime.put("安装五年以上", 1);
                            numtime++;
                        }
                    }
                } else {
                    if (mapTime.containsKey("不确定")) {
                        mapTime.put("不确定", mapTime.get("不确定") + 1);
                        numtime++;
                    } else {
                        mapTime.put("不确定", 1);
                        numtime++;
                    }
                }
            }
            List<Map<String,Object>> list = new ArrayList<>();
            for (Map.Entry<String, Integer> entry : mapTime.entrySet()) {
                Map<String,Object> maplist = new HashMap<String, Object>();
                maplist.put("time", entry.getKey());
                maplist.put("value", mapTime.get(entry.getKey()));
                maplist.put(
                        "percent",
                        String.format("%.2f", mapTime.get(entry.getKey())
                                / (double) numtime));
                list.add(maplist);
            }
            Collections.sort(list, new ComparatorMap());
            return list;
        }
        return null;
    }

    public List queryFaultDatas(String sql, String str) {
        List faultDatas = new ArrayList();
        System.out.println(sql);
        List<Map<String,Object>> objects = statisticsMapper.queryFaultStatistics(sql);
        int sum = 0;
        for (Map<String,Object> object : objects) {
            sum += Integer.parseInt(object.get("num").toString());
        }
        Map<String, Integer> fdmap = new HashMap<String, Integer>();
        for (Map<String,Object> object : objects) {
            if (fdmap.containsKey(object.get("name").toString())) {
                fdmap.put(object.get("name").toString(), fdmap.get(object.get("name").toString())
                        + Integer.parseInt(object.get("num").toString()));
            } else {
                fdmap.put(object.get("name").toString(),
                        Integer.parseInt(object.get("num").toString()));
            }
        }
        Map<String, Object> map = null;
        BigDecimal bg = null;
        for (Map.Entry<String, Integer> entry : fdmap.entrySet()) {
            map = new HashMap<String, Object>();
            int faultNum = entry.getValue();
            map.put(str, entry.getKey());
            map.put("value", faultNum);
            double num = (double) faultNum / sum;
            bg = BigDecimal.valueOf(num);
            double percent = bg.setScale(3, BigDecimal.ROUND_HALF_UP)
                    .doubleValue();
            map.put("percent", percent);
            faultDatas.add(map);
        }
        return faultDatas;
    }


    @Override
    public List<QualityList> queryQualityList(String userId, String stationId, Integer pageNum) {
        PageHelper.startPage(pageNum+1,20);
        List<QualityList> list = statisticsMapper.queryQualityList(userId);
        return list;
    }

    @Override
    public Quality queryQualityMessage(String qualityId){
        Quality quality = statisticsMapper.queryQualityMessage(qualityId);
        List<Image> images = statisticsMapper.queryImage(qualityId);
        StringBuffer picStr = new StringBuffer("");
        try {
            for(int i=0;i<images.size();i++){
                String name = images.get(i).getName();
                File fileDir = new File(photoPath+"/Quality");
                FileUtil.judeFileExists(fileDir);
                byte[] bytes =images.get(i).getPhoto();
                if(bytes!=null) {
                    FileUtil.createFile(photoPath+"/Quality", bytes, name);
                    StringBuffer sb = new StringBuffer();
                    if (i == images.size() - 1) {
                        picStr.append("http://" + imagePath + "/Quality/" + name);
                    } else {
                        picStr.append("http://" + imagePath + "/Quality/" + name + ",");
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        quality.setImages(picStr.toString());
        return quality;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveQuality(String userId, String time, String equipId, String num, String faultDisc, String discrib, String artisanId, String equipName, String receiveTime, MultipartFile[] images) throws IOException{
        Quality quality = new Quality();
        quality.setEquipId(Integer.parseInt(equipId));
        quality.setUserId(Integer.parseInt(userId));
        quality.setNum(Integer.parseInt(num));
        quality.setDisc(discrib);
        quality.setFaultDisc(faultDisc);
        quality.setTime(time);
        quality.setState(0);
        quality.setEquipName(equipName);
        quality.setReceiveTime(receiveTime);
        statisticsMapper.saveQuality(quality);
        List<Image> imageList = new ArrayList<>();
        if (images!=null) {
            for (int i = 0; i < images.length; i++) {
                Image image = new Image();
                image.setId(quality.getQualityId());
                String name = FormatUtil.getUUID() + images[i].getOriginalFilename().substring(images[i].getOriginalFilename().lastIndexOf("."));
                image.setName(name);
                image.setPhoto(images[i].getBytes());
                imageList.add(image);
            }
            if (imageList.size() != 0) {
                statisticsMapper.saveQualityImage(imageList);
            }
        }
    }

    @Override
    public List<NQualityList> queryQualityArtisanSqeList(String userId, String state, Integer pageNum) {
        UserInfoId infoId = userMapper.queryUserInfoId(userId);
        PageHelper.startPage(pageNum+1,20);
        List<NQualityList> list = statisticsMapper.queryQualityArtisanSqeList(state,userId,infoId.getPostId());
        return list;
    }

    @Override
    public void updateQualityArtisan(String suggestion, String time, String id, String sqeId, String userId) {
        statisticsMapper.updateQualityArtisan(userId,suggestion,time,1,id);
    }

    @Override
    public void updateQualitySqe(String scheme, String measures, String causes, String id, String time, String userId) {
        statisticsMapper.updateQualitySqe(userId,scheme,measures,causes,time,2,id);
    }

    @Override
    public List<SuggestionType> querySuggestionType() {
        List<SuggestionType> list = new ArrayList<>();
        SuggestionType suggestionType = new SuggestionType();
        suggestionType.setAspectId(1);
        suggestionType.setAspectName("技术问题");
        list.add(suggestionType);
        suggestionType = new SuggestionType();
        suggestionType.setAspectId(2);
        suggestionType.setAspectName("行政问题");
        list.add(suggestionType);
        suggestionType = new SuggestionType();
        suggestionType.setAspectId(3);
        suggestionType.setAspectName("备件问题");
        list.add(suggestionType);
        suggestionType = new SuggestionType();
        suggestionType.setAspectId(4);
        suggestionType.setAspectName("体系管理问题");
        list.add(suggestionType);
        suggestionType = new SuggestionType();
        suggestionType.setAspectId(5);
        suggestionType.setAspectName("其它");
        list.add(suggestionType);
        return list;
    }

    @Override
    public void saveSuggestion(String type, String anonymity, String aspectOn, String submitTime, String suggestion, String userId, String title) {
        if (!"1".equals(type) && !"2".equals(type)){
            throw new OperationException("建议上报失败");
        }
        statisticsMapper.saveSuggestion(type,userId,suggestion,aspectOn,anonymity,title);
    }

    @Override
    public List<Suggestion> querySuggestionList(Integer pageNum, String suggestionState, String sortType, String userId) {
        PageHelper.startPage(pageNum+1,20);
        List<Suggestion> list = statisticsMapper.querySuggestionList(userId,sortType,suggestionState);
        return list;
    }

    @Override
    public void querySupport(String suggestionId, String userId, String supportState) {
        Integer id = statisticsMapper.querySuggestionSupport(suggestionId,userId);
        if ("0".equals(supportState)) {
            if(id==null){
                throw new OperationException("赞已被取消");
            }else {
                statisticsMapper.deleteSuggestionSupport(suggestionId,userId);
            }
        }else if("1".equals(supportState)){
            if(id==null){
                statisticsMapper.saveSuggestionSupport(suggestionId,userId);
            }else {
                throw new OperationException("已赞");
            }
        }
    }

    @Override
    public List<Suggestion> searchSuggestion(Integer pageNum, String sortType, String startTime, String endTime, String suggestionType, String keyword, String branchId, String userId) {
        PageHelper.startPage(pageNum+1,20);
        List<Suggestion> list = statisticsMapper.searchSuggestion(userId,branchId,startTime,endTime,suggestionType,keyword,sortType);
        return list;
    }
}
